package com.briup.app02.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.briup.app02.bean.BaseUser;
import com.briup.app02.bean.BaseUserExample;
import com.briup.app02.bean.extend.BaseUserExtend;
import com.briup.app02.bean.extend.BaseUserRoleExtend;
import com.briup.app02.bean.extend.UserExtend;
import com.briup.app02.dao.BaseUserMapper;
import com.briup.app02.dao.extend.BaseRoleextendMapper;
import com.briup.app02.dao.extend.BaseUserExtendMapper;
import com.briup.app02.service.IBaseUserService;
import com.briup.app02.utils.Message;
import com.briup.app02.dao.extend.UserExtendMapper;

@Service
public class BaseUserServiceImpl implements IBaseUserService{
	@Autowired
	private BaseUserMapper baseusermapper;
	@Autowired
	private UserExtendMapper userExtendMapper;

	@Override
	public List<BaseUser> query(String username,String status) {
		BaseUserExample example = new BaseUserExample();
		BaseUserExample.Criteria criteria = example.createCriteria();
		if (username != null) {
			criteria.andUsernameEqualTo(username);
		}
		if (status != null) {
			criteria.andStatusEqualTo(status);
		}
		return baseusermapper.selectByExample(example);
	}

	@Override
	public BaseUser findUserDetailsById(long id) {
		return baseusermapper.selectByPrimaryKey(id);
	}

	@Override
	public void SaveOrUpdate(BaseUser baseuser) {
		if(baseuser.getId() == null) {
			baseusermapper.insert(baseuser);
		} else {
			baseusermapper.updateByPrimaryKey(baseuser);
		}
		
	}

	@Override
	public void deleteById(long id) {
		baseusermapper.deleteByPrimaryKey(id);
		
	}
	
	@Override
	public List<UserExtend>  CascadeQuery(String username,String status,String role){
		return userExtendMapper.CascadeQuery(username,status,role);
	}

	@Override
	public void addUser(BaseUser baseuser) {
		baseusermapper.insert(baseuser);
	}

	@Override
	public void alterUserface(Long id, String userface) {
		BaseUser baseuser=new BaseUser();
		if(id == baseuser.getId()) {
			baseusermapper.updateByPrimaryKey(baseuser);
		}
	}

	@Override
	public List<BaseUserExtend> pageQuery(int pageIndex, int pageSize, String username, String status, Long roleId) {
		int page = (pageIndex-1)*pageSize;
		return null;
	}
	
	}